Skip to content

Conversation

@stringintech
Copy link
Contributor

@stringintech stringintech commented Oct 26, 2024

This pull request addresses a bug in the isDirty method when dealing with ManyToOne associations that are referenced by a unique key instead of a primary key, particularly when the primary key is a custom type.

This bug stems from a mismatch in how isDirty checks for changes: while it correctly retrieves the unique key value using getIdentifier, it incorrectly relies on getIdentifierType, which only considers the primary key type. This results in unexpected behavior—in this case, a ClassCastException when attempting to call the custom ID type's equals method.

The fix replaces getIdentifierType with getIdentifierOrUniqueKeyType, ensuring that isDirty correctly accounts for both primary keys and unique keys. This issue is demonstrated in the unit test ManyToOneUniqueKeyReferenceWithCustomIdTest.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-18764

Copy link
Member

@mbellade mbellade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @stringintech could you please also test this on the 6.6 branch and provide a PR against it to backport the fix? Thanks!

@stringintech
Copy link
Contributor Author

Sure. Done.

@mbellade mbellade merged commit e676ebe into hibernate:main Oct 29, 2024
21 of 22 checks passed
@stringintech stringintech deleted the HHH-18764 branch October 29, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants